home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / lindex.test < prev    next >
Text File  |  1993-02-06  |  3KB  |  74 lines

  1. # Commands covered:  lindex
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/lindex.test,v 1.2 93/02/06 16:01:45 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. test lindex-1.1 {basic tests} {
  32.     lindex {a b c} 0} a
  33. test lindex-1.2 {basic tests} {
  34.     lindex {a {b c d} x} 1} {b c d}
  35. test lindex-1.3 {basic tests} {
  36.     lindex {a b\ c\ d x} 1} {b c d}
  37. test lindex-1.4 {basic tests} {
  38.     lindex {a b c} 3} {}
  39. test lindex-1.5 {basic tests} {
  40.     list [catch {lindex {a b c} -1} msg] $msg
  41. } {0 {}}
  42.  
  43. test lindex-2.1 {error conditions} {
  44.     list [catch {lindex msg} msg] $msg
  45. } {1 {wrong # args: should be "lindex list index"}}
  46. test lindex-2.2 {error conditions} {
  47.     list [catch {lindex 1 2 3 4} msg] $msg
  48. } {1 {wrong # args: should be "lindex list index"}}
  49. test lindex-2.3 {error conditions} {
  50.     list [catch {lindex 1 2a2} msg] $msg
  51. } {1 {expected integer but got "2a2"}}
  52. test lindex-2.4 {error conditions} {
  53.     list [catch {lindex "a \{" 2} msg] $msg
  54. } {1 {unmatched open brace in list}}
  55. test lindex-2.5 {error conditions} {
  56.     list [catch {lindex {a {b c}d e} 2} msg] $msg
  57. } {1 {list element in braces followed by "d" instead of space}}
  58. test lindex-2.6 {error conditions} {
  59.     list [catch {lindex {a "b c"def ghi} 2} msg] $msg
  60. } {1 {list element in quotes followed by "def" instead of space}}
  61.  
  62. test lindex-3.1 {quoted elements} {
  63.     lindex {a "b c" d} 1
  64. } {b c}
  65. test lindex-3.2 {quoted elements} {
  66.     lindex {"{}" b c} 0
  67. } {{}}
  68. test lindex-3.3 {quoted elements} {
  69.     lindex {ab "c d \" x" y} 1
  70. } {c d " x}
  71. test lindex-3.4 {quoted elements} {
  72.     lindex {a b {c d "e} {f g"}} 2
  73. } {c d "e}
  74.